/**
 * 管理后台路由
 */

const group = [
  { name: '资讯资源', icon: 'mail' },
  { name: '运营', icon: 'mail' },
  { name: '设置', icon: 'mail' },
];

const routes = [
  {
    path: '/dashboard/column_management',
    name: 'Columnmanage',
    meta: { group: '资讯资源', title: '栏目管理', hidden: false },
    component: () => import('@/views/dashboard/information/Columnmanage'),
  },
  {
    path: '/dashboard/news_list',
    name: 'Newslist',
    meta: { group: '资讯资源', title: '新闻列表', hidden: false },
    component: () => import('@/views/dashboard/information/Newslist'),
  },
  {
    path: '/dashboard/news_add',
    name: 'Newsadd',
    meta: { group: '资讯资源', title: '新闻添加', hidden: true },
    component: () => import('@/views/dashboard/information/Newsadd'),
  },
  {
    path: '/dashboard/news_modify',
    name: 'NewsUpdate',
    meta: { group: '资讯资源', title: '新闻修改', hidden: true },
    component: () => import('@/views/dashboard/information/NewsUpdate'),
  },
  {
    path: '/dashboard/news_details',
    name: 'Newsdetails',
    meta: { group: '资讯资源', title: '查看新闻', hidden: true },
    component: () => import('@/views/dashboard/information/Newsdetails'),
  },
  {
    path: '/dashboard/resource_list',
    name: 'Resourcelist',
    meta: { group: '资讯资源', title: '资源列表', hidden: false },
    component: () => import('@/views/dashboard/information/Resourcelist'),
  },
  {
    path: '/operate/information_list',
    name: 'Informationlist',
    meta: { group: '运营', title: '咨询名单', hidden: false },
    component: () => import('@/views/dashboard/operate/Informationlist'),
  },
  {
    path: '/operate/banner_manage',
    name: 'Bannermanage',
    meta: { group: '运营', title: 'banner管理', hidden: false },
    component: () => import('@/views/dashboard/operate/Bannermanage'),
  },
  {
    path: '/operate/expert_database',
    name: 'Expertdatabase',
    meta: { group: '运营', title: '专家智库', hidden: false },
    component: () => import('@/views/dashboard/operate/Expertdatabase'),
  },
  {
    path: '/setup/friend_link',
    name: 'Friendlink',
    meta: { group: '设置', title: '友情链接', hidden: false },
    component: () => import('@/views/dashboard/setup/Friendlink'),
  },
  {
    path: '/setup/user_manage',
    name: 'Usermanage',
    meta: { group: '设置', title: '用户管理', hidden: false },
    component: () => import('@/views/dashboard/setup/Usermanage'),
  },
];

/**--------------------------------------------下面的代码不要改------------------------------------------------- */
/**把路由合并到组内 */
for (let rt of routes) {
  let gp = findGroupByName(rt.meta.group); //找到改路由对应的组
  if (gp != null) {
    //如果没有children节点就动态添加一个空节点
    if (gp.children == undefined) {
      gp.children = [];
      gp.size = 0;
    }
    //把路由放到组中
    gp.children.push(rt);
    //判断该路由是否在菜单中显示出来
    if (!rt.meta.hidden) {
      gp.size++;
      gp.baseRoute = rt;
    }
  }
}

/**根据名字找到对应的组 */
function findGroupByName(name) {
  for (let g of group) {
    if (g.name == name) {
      return g;
    }
  }
  return null;
}

export default { routes, group };
